unit fBase;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.DBCtrls, Vcl.StdCtrls, DB, Vcl.Buttons;

type
  TfrmBase = class(TForm)
    stbInfo: TStatusBar;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmBase: TfrmBase;

implementation

{$R *.dfm}

procedure TfrmBase.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if FormStyle = fsMDIChild then
 Action := caFree;
end;

procedure TfrmBase.FormCreate(Sender: TObject);
begin
  stbInfo.Panels[0].Text := ClassName;
end;

procedure TfrmBase.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
   i: Integer;
begin
if Key = VK_F4 then
 if FindComponent('btnOk') <> nil then
   TBitBtn(FindComponent('btnOk')).Click;

if Key = VK_F5 then
for i := 0 to Self.ComponentCount - 1 do
  if (Self.Components[i] is TDataSource) then
  begin
    (Self.Components[i] as TDataSource).DataSet.Close;
    (Self.Components[i] as TDataSource).DataSet.Open;
  end;

if Key = VK_ESCAPE then
   Close;
end;

procedure TfrmBase.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
  if ((not (Self.ActiveControl is TDBRichEdit)) and
      (not (Self.ActiveControl is TDBMemo)) and
      (not (Self.ActiveControl is TMemo)) and
      (not (Self.ActiveControl is TRichEdit))) then
      begin
        Perform (WM_NEXTDLGCTL, 0, 0);
        Key := #0;
      end;
end;

end.
